#EFFECT MODEL
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from game.combat.models import damageModifierCollection

class singleEffect(models.Model):
	"""A Single Effect that can be applied"""
	name = models.CharField(max_length=20, unique= True)
	content_type = models.ForeignKey(ContentType, null = True)
	object_id = models.PositiveIntegerField(null = True)
	content_object = generic.GenericForeignKey('content_type', 'object_id')
	damageSensitive = models.BooleanField(default = 0)
	multiplier = models.IntegerField(default = 1)
	
	def __unicode__(self):
		return self.name
		
	def getStat(self, stat):
		if type(self.content_object) == StatModifier:
			if self.content_object.name == stat:
				return self.multiplier
		return 0	
			
class effectInstance(models.Model):
	effect = models.ForeignKey('singleEffect')
	effectCollection = models.ForeignKey('effectCollection')
	duration = models.IntegerField(null = True)
	
class effectCollection(models.Model):
	#effects = models.ManyToManyField(singleEffect, through='effectInstance',
	#			null= True)
				
	def getStat(self, stat):
		""" returns the overall bonus from all effects fo the stat """
		total=0
		for ef in self.effects.all():
			total+=ef.getStat(stat)
		return total
			
class statModifier(models.Model):
	""" Holds the name of stats that can be modified """
	name = models.CharField(max_length=20, unique= True )
